const Mock = require('mockjs')
const Random = Mock.Random

const data = Mock.mock({
  'items|50': [{
    id: '@increment',
    oid: Random.id(),
    time: '@date(2021-MM-dd)',
    'name|1': '@cname',
    'money|1': '￥@integer(100,1000)',
    'pay|+1': [
      '未支付',
      '微信支付',
      '支付宝支付'],
    'source|1': [
      'APP订单',
      '实体店订单'
    ],
    'status|+1': [
      '已关闭',
      '已发货',
      '待发货',
      '已完成']
  }]
})

module.exports = [
  {
    url: '/vue-admin-template/student/list',
    type: 'get',
    response: config => {
      const { page = 1, limit = 20, name } = config.query
      const mockList = data.items.filter(item => {
        if (name && item.name.indexOf(name) < 0) return false
        return true
      })
      // compute page list according to page size and page index
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/vue-admin-template/student/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  {
    url: '/vue-admin-template/student/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
